#include "stdafx.h"
#include "BaseObject.h"
#include "xrender.h"
#include "TextureManager.h"

BaseObject::BaseObject()
{
	m_Velocity = D3DXVECTOR3(0.0f,0.0f,0.0f);
	m_eType = BASEOBJECT;
	m_xFile = NULL;
}

BaseObject::~BaseObject()
{
	SAFE_DELETE(m_xFile);
}

void BaseObject::ApplyTransfomationMatrixToRenderer()
{
}

void BaseObject::SetPosition(D3DXVECTOR3& pos)
{ 
	m_Position = pos; 
	if(m_xFile)
	{
		m_xFile->m_frame.m_mat._41 = m_Position.x;
		m_xFile->m_frame.m_mat._42 = m_Position.y;
		m_xFile->m_frame.m_mat._43 = m_Position.z;
		XUpdate(m_xFile);
	}

}

void BaseObject::Update(float _dt)
{
	m_xFile->m_frame.m_mat._41 += m_Velocity.x;
	m_xFile->m_frame.m_mat._42 += m_Velocity.y;
	m_xFile->m_frame.m_mat._43 += m_Velocity.z;
	XUpdate(m_xFile);
}

void BaseObject::LoadMesh(const char *fileLocation)
{
	m_xFile = new stXFile;
	LoadXTxtFile(m_xFile, fileLocation);
}

void BaseObject::Render()
{
	XRender(m_xFile);
}

BaseObject2D::BaseObject2D()
{
	m_eType = BASEOBJECT2D;
	m_fScaleX = 1.0f;
	m_fScaleY = 1.0f;
	m_fRotCenterX = 0.0f;
	m_fRotCenterY = 0.0f;
	m_fRotation = 0.0f;
	m_pSection.left = m_pSection.right = m_pSection.top = m_pSection.bottom = 0;
	m_dwColor = -1;
}

void BaseObject2D::SetTextureID(int ID)
{
	m_nTextureID = ID;
	m_pSection.bottom = TextureManager::GetInstance()->GetTextureHeight(m_nTextureID);
	m_pSection.right = TextureManager::GetInstance()->GetTextureWidth(m_nTextureID);
}

BaseObject2D::~BaseObject2D(void)
{
}

void BaseObject2D::Update(float _dt)
{

}

void BaseObject2D::Render()
{
	TextureManager::GetInstance()->Draw(m_nTextureID, (int)m_vPosition.x, (int)m_vPosition.y, m_fScaleX, m_fScaleY, &m_pSection, m_fRotCenterX, m_fRotCenterY, m_fRotation, m_dwColor);
}